package com.bw.auth.utils;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
 
import java.util.Set;
 
@Component
public class RedisUtils {
    RedisTemplate<Object, Object> redisTemplate;
 
    public RedisUtils(RedisTemplate<Object, Object> redisTemplate) {
        this.redisTemplate = redisTemplate;
    }
 
    /**
     * 添加
     *
     * @param key   键
     * @param value 数据项
     * @param score 分数
     * @return
     */
    public void add(String key, String value, long score) {
        redisTemplate.opsForZSet().add(key, value, score);
    }
 
    /**
     * 获取
     *
     * @param key   键
     * @param start 起始
     * @param end   结束
     * @return
     */
    public Set<Object> rangeByScore(String key, long start, long end) {
        return redisTemplate.opsForZSet().rangeByScore(key, start, end);
    }
 
    /**
     * 统计
     *
     * @param key   键
     * @param start 起始
     * @param end   结束
     * @return
     */
    public Long count(String key, long start, long end) {
        return redisTemplate.opsForZSet().count(key, start, end);
    }
 
    /**
     * 删除
     *
     * @param key   键
     * @param value 数据项
     * @return
     */
    public Long zrem(String key, String value) {
        return redisTemplate.opsForZSet().remove(key, value);
    }
}
